<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 250px;
            height: 400px;
            background-color: red;
            display: none;
            position: absolute;
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>

</html>
<script>
    //模拟右键菜单
    var oBox = document.querySelector('.box');
    document.oncontextmenu = function(ev) {
        var ev = ev || event;
        oBox.style.display = 'block';
        //获取可视区的鼠标位置，赋值给left和top
        oBox.style.left = ev.clientX + 'px';
        oBox.style.top = ev.clientY + 'px';
        return false;
    };

    //点击左键，盒子消失
    document.onclick = function() {
        oBox.style.display = 'none';
    }
</script>